import service from "@/utils/request";
import type {
  ArrayCategory1,
  ArrayCategory2,
  ArrayCategory3,
  productType,
  productIdType,
  addAttr,
  spuType,
  salesObj,
} from "./model/index";
enum api {
  urlCategory1 = "/admin/product/getCategory1",
  urlCategory2 = "/admin/product/getCategory2",
  urlCategory3 = "/admin/product/getCategory3",
  urlPoductType = "/admin/product/attrInfoList",
  urlAddAttrValue = "/admin/product/saveAttrInfo",
  urlDeleteAttr = "/admin/product/deleteAttr",
  urlSpu = "/admin/product",
  urlSale = "/admin/product/baseSaleAttrList",
}
export function reqCategory1() {
  return service.get<null, ArrayCategory1>(api.urlCategory1);
}
export function reqCategory2(category1Id: number) {
  return service.get<null, ArrayCategory2>(
    api.urlCategory2 + `/${category1Id}`
  );
}
export function reqCategory3(category2Id: number) {
  return service.get<null, ArrayCategory3>(
    api.urlCategory3 + `/${category2Id}`
  );
}
export function reqProducType({
  category1Id,
  category2Id,
  category3Id,
}: productIdType) {
  return service.get<null, productType>(
    api.urlPoductType + `/${category1Id}/${category2Id}/${category3Id}`
  );
}
//添加品牌属性
export function reqAddAttr(attr: addAttr) {
  return service.post<null, any>(api.urlAddAttrValue, attr);
}
export function reqDeleteAttr(attrId: number) {
  return service.delete(api.urlDeleteAttr + `/${attrId}`);
}
export function reqSpuList(page: number, limit: number, category3Id: number) {
  return service.get<null, spuType>(api.urlSpu + `/${page}/${limit}`, {
    params: { category3Id },
  });
}
export function reqSales() {
  return service.get<null, salesObj[]>(api.urlSale);
}
